#ifndef __APP_BUFFER_H
#define __APP_BUFFER_H
#include "app_common.h"
#include "pthread.h"

// 子缓冲区结构体
typedef struct
{
    uint8_t *ptr; // 缓冲区指针
    int capacity; // 缓冲区容量
    int len;      // 已经存储的数据的长度
} sub_buffer_t;

// 缓冲区结构体
typedef struct
{
    sub_buffer_t *sub_buffers[2];
    int read_index;  // 哪个缓冲区用来读
    int write_index; // 哪个缓冲区用来写

    pthread_mutex_t r_mutext; // 读锁
    pthread_mutex_t w_mutext; // 写锁
} buffer_t;

buffer_t *app_buffer_init(int capacity);
void app_buffer_deInit(buffer_t *buffer);
gate_status_t app_buffer_write(buffer_t *buffer, uint8_t *data, uint8_t len);
uint8_t app_buffer_read(buffer_t *buffer, uint8_t *data, int data_capacity);
#endif
